/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.swirrel.listener;

import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelListDataListener
    extends AbstractSwirrelListener implements ListDataListener {

  private final MethodCall contentsChangedTuple;
  private final MethodCall intervalAddedTuple;
  private final MethodCall intervalRemovedTuple;

  public SwirrelListDataListener(
      MethodCall contentsChangedTuple,
      MethodCall intervalAddedTuple,
      MethodCall intervalRemovedTuple) {
    this.contentsChangedTuple = contentsChangedTuple;
    this.intervalAddedTuple = intervalAddedTuple;
    this.intervalRemovedTuple = intervalRemovedTuple;
    if (!checkSignature(contentsChangedTuple, ListDataEvent.class) ||
        !checkSignature(intervalAddedTuple, ListDataEvent.class) ||
        !checkSignature(intervalRemovedTuple, ListDataEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one ListDataEvent argument");
    }
  }

  public void contentsChanged(ListDataEvent e) {
    call(contentsChangedTuple, e);
  }

  public void intervalAdded(ListDataEvent e) {
    call(intervalAddedTuple, e);
  }

  public void intervalRemoved(ListDataEvent e) {
    call(intervalRemovedTuple, e);
  }

}
